package com.longmao.eduservice.controller;


import com.longmao.commonutils.R;
import com.longmao.eduservice.entity.EduChapter;
import com.longmao.eduservice.entity.EduVideo;
import com.longmao.eduservice.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author longmao
 * @since 2022-01-27
 */
@RestController
//@CrossOrigin
@RequestMapping("/eduservice/video")
public class EduVideoController {

    @Autowired
    private EduVideoService videoService;

    @PostMapping("/addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo) {
        boolean result = videoService.save(eduVideo);
        if(result) {
            return R.ok();
        }else {
            return R.error().message("添加失败");
        }
    }

    @PostMapping("/updateVideo")
    public R updateVideoById(@RequestBody EduVideo eduVideo) {
        boolean result = videoService.updateById(eduVideo);
        if(result) {
            return R.ok();
        }else {
            return R.error().message("修改失败");
        }
    }

    @DeleteMapping("/deleteVideo/{videoId}")
    public R deleteVideoById(@PathVariable String videoId) {
        boolean result = videoService.deleteVideoById(videoId);
        if(result) {
            return R.ok();
        }else {
            return R.error().message("删除失败");
        }
    }

    @GetMapping("/getVideoInfo/{videoId}")
    public R getVideoInfo(@PathVariable String videoId) {
        EduVideo eduVideo = videoService.getById(videoId);
        return R.ok().data("eduVideo", eduVideo);
    }
}

